package com.tsmti.util;

import com.tsmti.basicdata.entity.*;
import com.tsmti.business.entity.PimsSysPathology;
import com.tsmti.core.common.constant.RedisConstants;
import com.tsmti.core.util.RedisUtils;
import com.tsmti.core.util.StringUtils;
import com.tsmti.system.entity.Organization;
import com.tsmti.system.entity.User;

import java.util.Map;

;

/**
 * @path：com.tsmti.lab.util
 * @author: ft
 * @time: 2018/7/9 14:13
 * @Description:
 */
public class RedisGridFormatUtils {

    public static String getGridFormatValues(String key) throws Exception {
        String values = "";
        Object map = RedisUtils.getObject(key);
        switch (key) {
            case RedisConstants.ORGANIZATION_CACHE:
                Map<String, Organization> organizationMap = (Map<String, Organization>) map;
                for (String keys : organizationMap.keySet()) {
                    if (!StringUtils.isEmpty(values)) {
                        values += ";";
                    }
                    values += keys + ":" + organizationMap.get(keys).getName();
                }
                break;
            case RedisConstants.USER_CACHE:
                Map<String, User> userMap = (Map<String, User>) map;
                for (String keys : userMap.keySet()) {
                    if (!StringUtils.isEmpty(values)) {
                        values += ";";
                    }
                    values += keys + ":" + userMap.get(keys).getRealName();
                }
                break;
            case RedisConstants.WARD_CACHE:
                Map<String, WardInformation> wardInformationMap = (Map<String, WardInformation>) map;
                for (String keys : wardInformationMap.keySet()) {
                    if (!StringUtils.isEmpty(values)) {
                        values += ";";
                    }
                    values += wardInformationMap.get(keys).getCode() + ":" + wardInformationMap.get(keys).getName();
                }
                break;
            case RedisConstants.DEPT_CACHE:
                Map<String, DeptInfomation> deptInfomationMap = (Map<String, DeptInfomation>) map;
                for (String keys : deptInfomationMap.keySet()) {
                    if (!StringUtils.isEmpty(values)) {
                        values += ";";
                    }
                    values += keys + ":" + deptInfomationMap.get(keys).getName();
                }
                break;
            case RedisConstants.DOCTORANDNURSE_CACHE:
                Map<String, DoctorInformation> doctorInformationMap = (Map<String, DoctorInformation>) map;
                for (String k : doctorInformationMap.keySet()) {
                    if (!StringUtils.isEmpty(values)) {
                        values += ";";
                    }
                    values += doctorInformationMap.get(k).getCode() + ":" + doctorInformationMap.get(k).getName();
                }
                break;
            case RedisConstants.SYS_PATHOLOGY:
                Map<String, PimsSysPathology> sysPathologyMap = (Map<String, PimsSysPathology>) map;
                for (String k : sysPathologyMap.keySet()) {
                    if (!StringUtils.isEmpty(values)) {
                        values += ";";
                    }
                    values += sysPathologyMap.get(k).getId() + ":" + sysPathologyMap.get(k).getPatNamech();
                }
                break;
            default:
                return "";
        }
        return values;
    }

    public static String getSelectOptions(String key,String value) throws Exception {
        String values = "";
        Object map = RedisUtils.getObject(key);
        switch (key) {
            case RedisConstants.ORGANIZATION_CACHE:
                Map<String, Organization> organizationMap = (Map<String, Organization>) map;
                for (String k : organizationMap.keySet()) {
                    if (!StringUtils.isEmpty(values)) {
                        values += "\n";
                    }
                    values +="<option value ="+k;
                    if(StringUtils.isNotEmpty(value) && k.equals(value)){
                        values += " selected = selected ";

                    }
                    values += ">"+organizationMap.get(k).getName()+"</option>";
                }
                break;
            case RedisConstants.USER_CACHE:
                Map<String, User> userMap = (Map<String, User>) map;
                for (String k : userMap.keySet()) {
                    if (!StringUtils.isEmpty(values)) {
                        values += "\n";
                    }
                    values +="<option value ="+k;
                    if(StringUtils.isNotEmpty(value) && k.equals(value)){
                        values += " selected = selected ";

                    }
                    values += ">"+userMap.get(k).getRealName()+"</option>";
                }
                break;
            case RedisConstants.WARD_CACHE:
                Map<String, WardInformation> wardInformationMap = (Map<String, WardInformation>) map;
                for (String keys : wardInformationMap.keySet()) {
                    if (!StringUtils.isEmpty(values)) {
                        values += "\n";
                    }
                    values +="<option value ="+wardInformationMap.get(keys).getCode();
                    if(StringUtils.isNotEmpty(value) && wardInformationMap.get(keys).getCode().equals(value)){
                        values += " selected = selected ";

                    }
                    values += ">"+wardInformationMap.get(keys).getName()+"</option>";
                }
                break;
            case RedisConstants.DEPT_CACHE:
                Map<String, DeptInfomation> deptInfomationMap = (Map<String, DeptInfomation>) map;
                for (String k : deptInfomationMap.keySet()) {
                    if (!StringUtils.isEmpty(values)) {
                        values += "\n";
                    }
                    values +="<option value ="+k;
                    if(StringUtils.isNotEmpty(value) && k.equals(value)){
                        values += " selected = selected ";

                    }
                    values += ">"+deptInfomationMap.get(k).getName()+"</option>";
                }
                break;
            case RedisConstants.DOCTORANDNURSE_CACHE:
                Map<String, DoctorInformation> doctorInformationMap = (Map<String, DoctorInformation>) map;
                for (String k : doctorInformationMap.keySet()) {
                    if (!StringUtils.isEmpty(values)) {
                        values += "\n";
                    }
                    values += doctorInformationMap.get(k).getCode() + ":" + doctorInformationMap.get(k).getName();
                }
                break;
            case RedisConstants.SYS_PATHOLOGY:
                Map<String, PimsSysPathology> sysPathologyMap = (Map<String, PimsSysPathology>) map;
                for (String k : sysPathologyMap.keySet()) {
                    if (!StringUtils.isEmpty(values)) {
                        values += "\n";
                    }
                    values +="<option value ="+k;
                    if(StringUtils.isNotEmpty(value) && k.equals(value)){
                        values += " selected = selected ";

                    }
                    values += ">"+sysPathologyMap.get(k).getPatNamech()+"</option>";
                }
                break;
            default:
                return "";
        }
        return values;
    }

}
